{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9267302-d736-48dc-a752-4ecb2dd3d654",
   "metadata": {},
   "source": [
    "# pandas基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c590ef92-5fe7-4a94-a08c-11de84b578cb",
   "metadata": {},
   "source": [
    "df：任意的Pandas DataFrame对象\n",
    "\n",
    "s：任意的Pandas Series对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa3b18f6-9e19-40f0-9e7e-dfdbeb4c0680",
   "metadata": {},
   "source": [
    "> 请注意，xlwt库只支持旧版Excel文件（.xls格式），因此不能直接保存为新版Excel文件（.xlsx格式）。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56453e94-d734-4a44-866c-267c3e18114d",
   "metadata": {},
   "source": [
    "```python\n",
    "# 读入文件\n",
    "\n",
    "filename = \"\"\n",
    "url=\"\"\n",
    "json_string = \"\"\n",
    "pd.read_csv(filename); \t\t\t\t\t\t # 从CSV文件导入数据\n",
    "pd.read_table(filename); \t\t\t\t\t # 从限定分隔符的文本文件导入数据\n",
    "pd.read_excel(filename); \t\t\t\t\t # 从Excel文件导入数据\n",
    "pd.read_sql(query, connection_object);\t\t  # 从SQL表/库导入数据\n",
    "pd.read_json(json_string); \t\t\t\t\t # 从JSON格式的字符串导入数据\n",
    "pd.read_html(url); \t\t\t\t\t\t\t# 解析URL、字符串或者HTML文件，抽取其中的tables表格\n",
    "pd.read_clipboard(); \t\t\t\t\t\t# 从你的粘贴板获取内容，并传给read_table()\n",
    "pd.DataFrame(dict); \t\t\t\t\t\t# 从字典对象导入数据，Key是列名，Value是数据\n",
    "# ...\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b9b8930-e6a6-4681-8fc3-ef87676b8587",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9cffd2f7-8c16-4855-8acb-a792524db4d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4b3d190e-084a-4448-b79b-530cc5989b43",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "Missing optional dependency 'xlrd'. Install xlrd >= 2.0.1 for xls Excel support Use pip or conda to install xlrd.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\compat\\_optional.py:132\u001b[0m, in \u001b[0;36mimport_optional_dependency\u001b[1;34m(name, extra, errors, min_version)\u001b[0m\n\u001b[0;32m    131\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 132\u001b[0m     module \u001b[38;5;241m=\u001b[39m importlib\u001b[38;5;241m.\u001b[39mimport_module(name)\n\u001b[0;32m    133\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\importlib\\__init__.py:126\u001b[0m, in \u001b[0;36mimport_module\u001b[1;34m(name, package)\u001b[0m\n\u001b[0;32m    125\u001b[0m         level \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m--> 126\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _bootstrap\u001b[38;5;241m.\u001b[39m_gcd_import(name[level:], package, level)\n",
      "File \u001b[1;32m<frozen importlib._bootstrap>:1204\u001b[0m, in \u001b[0;36m_gcd_import\u001b[1;34m(name, package, level)\u001b[0m\n",
      "File \u001b[1;32m<frozen importlib._bootstrap>:1176\u001b[0m, in \u001b[0;36m_find_and_load\u001b[1;34m(name, import_)\u001b[0m\n",
      "File \u001b[1;32m<frozen importlib._bootstrap>:1140\u001b[0m, in \u001b[0;36m_find_and_load_unlocked\u001b[1;34m(name, import_)\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'xlrd'",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[7], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m pd\u001b[38;5;241m.\u001b[39mread_excel(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata/KeyDevelopment Screening Report.xls\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:504\u001b[0m, in \u001b[0;36mread_excel\u001b[1;34m(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend, engine_kwargs)\u001b[0m\n\u001b[0;32m    502\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(io, ExcelFile):\n\u001b[0;32m    503\u001b[0m     should_close \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m--> 504\u001b[0m     io \u001b[38;5;241m=\u001b[39m ExcelFile(\n\u001b[0;32m    505\u001b[0m         io,\n\u001b[0;32m    506\u001b[0m         storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m    507\u001b[0m         engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m    508\u001b[0m         engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m    509\u001b[0m     )\n\u001b[0;32m    510\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m engine \u001b[38;5;129;01mand\u001b[39;00m engine \u001b[38;5;241m!=\u001b[39m io\u001b[38;5;241m.\u001b[39mengine:\n\u001b[0;32m    511\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m    512\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEngine should not be specified when passing \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m    513\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124man ExcelFile - ExcelFile already has the engine set\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m    514\u001b[0m     )\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1580\u001b[0m, in \u001b[0;36mExcelFile.__init__\u001b[1;34m(self, path_or_buffer, engine, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m   1577\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mengine \u001b[38;5;241m=\u001b[39m engine\n\u001b[0;32m   1578\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstorage_options \u001b[38;5;241m=\u001b[39m storage_options\n\u001b[1;32m-> 1580\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_reader \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engines[engine](\n\u001b[0;32m   1581\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_io,\n\u001b[0;32m   1582\u001b[0m     storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m   1583\u001b[0m     engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m   1584\u001b[0m )\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_xlrd.py:44\u001b[0m, in \u001b[0;36mXlrdReader.__init__\u001b[1;34m(self, filepath_or_buffer, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m     32\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m     33\u001b[0m \u001b[38;5;124;03mReader using xlrd engine.\u001b[39;00m\n\u001b[0;32m     34\u001b[0m \n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m     41\u001b[0m \u001b[38;5;124;03m    Arbitrary keyword arguments passed to excel engine.\u001b[39;00m\n\u001b[0;32m     42\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m     43\u001b[0m err_msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInstall xlrd >= 2.0.1 for xls Excel support\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m---> 44\u001b[0m import_optional_dependency(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxlrd\u001b[39m\u001b[38;5;124m\"\u001b[39m, extra\u001b[38;5;241m=\u001b[39merr_msg)\n\u001b[0;32m     45\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(\n\u001b[0;32m     46\u001b[0m     filepath_or_buffer,\n\u001b[0;32m     47\u001b[0m     storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m     48\u001b[0m     engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m     49\u001b[0m )\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\compat\\_optional.py:135\u001b[0m, in \u001b[0;36mimport_optional_dependency\u001b[1;34m(name, extra, errors, min_version)\u001b[0m\n\u001b[0;32m    133\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m:\n\u001b[0;32m    134\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m errors \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraise\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 135\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(msg)\n\u001b[0;32m    136\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m    138\u001b[0m \u001b[38;5;66;03m# Handle submodules: if we have submodule, grab parent module from sys.modules\u001b[39;00m\n",
      "\u001b[1;31mImportError\u001b[0m: Missing optional dependency 'xlrd'. Install xlrd >= 2.0.1 for xls Excel support Use pip or conda to install xlrd."
     ]
    }
   ],
   "source": [
    "pd.read_excel(r\"data/KeyDevelopment Screening Report.xls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "05f0137d-39c1-4fa6-bbd3-13f8f7736c87",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting xlrd\n",
      "  Downloading xlrd-2.0.1-py2.py3-none-any.whl (96 kB)\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------------- 96.5/96.5 kB 162.5 kB/s eta 0:00:00\n",
      "Installing collected packages: xlrd\n",
      "Successfully installed xlrd-2.0.1\n"
     ]
    }
   ],
   "source": [
    "!pip install xlrd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e74a427e-1882-48ab-aed2-d4c558c0b14a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "data = pd.read_excel(r\"data/KeyDevelopment Screening Report.xls\").sample(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4094391b-3d79-49a3-87dc-25cefedfe1ca",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "No engine for filetype: 'xls'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOptionError\u001b[0m                               Traceback (most recent call last)",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1153\u001b[0m, in \u001b[0;36mExcelWriter.__new__\u001b[1;34m(cls, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs)\u001b[0m\n\u001b[0;32m   1152\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1153\u001b[0m     engine \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mget_option(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mio.excel.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.writer\u001b[39m\u001b[38;5;124m\"\u001b[39m, silent\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m   1154\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m engine \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mauto\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:272\u001b[0m, in \u001b[0;36mCallableDynamicDoc.__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m    271\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m T:\n\u001b[1;32m--> 272\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__func__\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:146\u001b[0m, in \u001b[0;36m_get_option\u001b[1;34m(pat, silent)\u001b[0m\n\u001b[0;32m    145\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_get_option\u001b[39m(pat: \u001b[38;5;28mstr\u001b[39m, silent: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Any:\n\u001b[1;32m--> 146\u001b[0m     key \u001b[38;5;241m=\u001b[39m _get_single_key(pat, silent)\n\u001b[0;32m    148\u001b[0m     \u001b[38;5;66;03m# walk the nested dict\u001b[39;00m\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:132\u001b[0m, in \u001b[0;36m_get_single_key\u001b[1;34m(pat, silent)\u001b[0m\n\u001b[0;32m    131\u001b[0m         _warn_if_deprecated(pat)\n\u001b[1;32m--> 132\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m OptionError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo such keys(s): \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mrepr\u001b[39m(pat)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m    133\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(keys) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
      "\u001b[1;31mOptionError\u001b[0m: No such keys(s): 'io.excel.xls.writer'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[23], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m data\u001b[38;5;241m.\u001b[39mto_excel(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata.xls\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\generic.py:2345\u001b[0m, in \u001b[0;36mNDFrame.to_excel\u001b[1;34m(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, inf_rep, freeze_panes, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m   2332\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mio\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mformats\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexcel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ExcelFormatter\n\u001b[0;32m   2334\u001b[0m formatter \u001b[38;5;241m=\u001b[39m ExcelFormatter(\n\u001b[0;32m   2335\u001b[0m     df,\n\u001b[0;32m   2336\u001b[0m     na_rep\u001b[38;5;241m=\u001b[39mna_rep,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   2343\u001b[0m     inf_rep\u001b[38;5;241m=\u001b[39minf_rep,\n\u001b[0;32m   2344\u001b[0m )\n\u001b[1;32m-> 2345\u001b[0m formatter\u001b[38;5;241m.\u001b[39mwrite(\n\u001b[0;32m   2346\u001b[0m     excel_writer,\n\u001b[0;32m   2347\u001b[0m     sheet_name\u001b[38;5;241m=\u001b[39msheet_name,\n\u001b[0;32m   2348\u001b[0m     startrow\u001b[38;5;241m=\u001b[39mstartrow,\n\u001b[0;32m   2349\u001b[0m     startcol\u001b[38;5;241m=\u001b[39mstartcol,\n\u001b[0;32m   2350\u001b[0m     freeze_panes\u001b[38;5;241m=\u001b[39mfreeze_panes,\n\u001b[0;32m   2351\u001b[0m     engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m   2352\u001b[0m     storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m   2353\u001b[0m     engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m   2354\u001b[0m )\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\formats\\excel.py:946\u001b[0m, in \u001b[0;36mExcelFormatter.write\u001b[1;34m(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m    942\u001b[0m     need_save \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m    943\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    944\u001b[0m     \u001b[38;5;66;03m# error: Cannot instantiate abstract class 'ExcelWriter' with abstract\u001b[39;00m\n\u001b[0;32m    945\u001b[0m     \u001b[38;5;66;03m# attributes 'engine', 'save', 'supported_extensions' and 'write_cells'\u001b[39;00m\n\u001b[1;32m--> 946\u001b[0m     writer \u001b[38;5;241m=\u001b[39m ExcelWriter(  \u001b[38;5;66;03m# type: ignore[abstract]\u001b[39;00m\n\u001b[0;32m    947\u001b[0m         writer,\n\u001b[0;32m    948\u001b[0m         engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m    949\u001b[0m         storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m    950\u001b[0m         engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m    951\u001b[0m     )\n\u001b[0;32m    952\u001b[0m     need_save \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    954\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1157\u001b[0m, in \u001b[0;36mExcelWriter.__new__\u001b[1;34m(cls, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs)\u001b[0m\n\u001b[0;32m   1155\u001b[0m             engine \u001b[38;5;241m=\u001b[39m get_default_engine(ext, mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwriter\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m   1156\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m-> 1157\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo engine for filetype: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m   1159\u001b[0m \u001b[38;5;66;03m# for mypy\u001b[39;00m\n\u001b[0;32m   1160\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m engine \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
      "\u001b[1;31mValueError\u001b[0m: No engine for filetype: 'xls'"
     ]
    }
   ],
   "source": [
    "data.to_excel(r\"data.xls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "3df3f376-57b4-4a6d-a5f4-0e9268904a02",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyexcel-xls\n",
      "  Downloading pyexcel_xls-0.7.0-py2.py3-none-any.whl (11 kB)\n",
      "Collecting pyexcel-xlsx\n",
      "  Downloading pyexcel_xlsx-0.6.0-py2.py3-none-any.whl (9.6 kB)\n",
      "Collecting pyexcel-io>=0.6.2 (from pyexcel-xls)\n",
      "  Downloading pyexcel_io-0.6.6-py2.py3-none-any.whl (44 kB)\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     --------------------------------------- 44.2/44.2 kB 18.9 kB/s eta 0:00:00\n",
      "Requirement already satisfied: xlrd in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xls) (2.0.1)\n",
      "Requirement already satisfied: xlwt in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xls) (1.3.0)\n",
      "Requirement already satisfied: openpyxl>=2.6.1 in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xlsx) (3.0.10)\n",
      "Requirement already satisfied: et_xmlfile in c:\\users\\666\\anaconda3\\lib\\site-packages (from openpyxl>=2.6.1->pyexcel-xlsx) (1.1.0)\n",
      "Collecting lml>=0.0.4 (from pyexcel-io>=0.6.2->pyexcel-xls)\n",
      "  Downloading lml-0.1.0-py2.py3-none-any.whl (10 kB)\n",
      "Installing collected packages: lml, pyexcel-io, pyexcel-xlsx, pyexcel-xls\n",
      "Successfully installed lml-0.1.0 pyexcel-io-0.6.6 pyexcel-xls-0.7.0 pyexcel-xlsx-0.6.0\n"
     ]
    }
   ],
   "source": [
    "!pip install pyexcel-xls pyexcel-xlsx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "d386cfff-8ee0-48a5-8242-f1a6c9bfec5c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "data.to_excel(r\"data.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45984029-3c0b-4d23-8eb2-b64d5b831fa9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
